package com.example.softwareconfigurationcoursedesign.Admin;

import com.example.softwareconfigurationcoursedesign.ShopPage.Product;
import com.example.softwareconfigurationcoursedesign.ShopPage.ProductService;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.List;

// 查找商品
@WebServlet("/searchProduct")
public class SearchProductServlet extends HttpServlet {
    // 处理GET请求
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 获取请求参数中的搜索关键词
        String searchKeyword = request.getParameter("searchKeyword");
        // 创建ProductServiceImplement对象
        ProductServiceImplement productServiceImplement = new ProductService();
        // 调用searchProduct方法进行产品搜索
        List<Product> productList = productServiceImplement.searchProduct(searchKeyword);
        // 将搜索结果存入request属性中
        request.setAttribute("productList", productList);
        // 转发请求到searchResults.jsp页面
        request.getRequestDispatcher("searchResults.jsp").forward(request, response);
    }
}

